package magicboard.model
{
  import flash.geom.Point;
  
  /**
  * infinitive line in 2D space
  */
  public class Line
  {
    // --------------------------------------------------------------------------------------------
    
    public function Line(p1:Point, p2:Point)
    {
      _p1 = p1;
      _p2 = p2;
    }

    // --------------------------------------------------------------------------------------------
    /** distance from point to line */
    public function distanceTo(p: Point):Number{
      var v:Vector = Vector.points2Vector(_p1,_p2);
      var c2:Number = Vector.dot(v,v);

      var w:Vector = Vector.points2Vector(_p1,p);
      var c1:Number = Vector.dot(w,v);
      var b:Number = c1/c2; 
      var pb:Point = new Point(_p1.x + b * v.x, _p1.y + b * v.y);             //      Point Pb = L.P0 + b * v;

      return p.subtract(pb).length;
    }

    // --------------------------------------------------------------------------------------------
    // Private members
    private var _p1:Point;
    private var _p2:Point;
  }
}